//
//  WXSearchView.swift
//  WXWeiBo
//
//  Created by Angel-xin on 2016/09/19.
//  Copyright © 2016年 Angel-xin. All rights reserved.
//

import UIKit

class WXSearchView: UIView {

    /*
    // Only override draw() if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func draw(_ rect: CGRect) {
        // Drawing code
    }
    */
    @IBOutlet weak var searchButton: UIButton!

    @IBOutlet weak var searchTextField: UITextField!
    
    @IBOutlet weak var searchTextFieldRightConstraint: NSLayoutConstraint!
    
    @IBAction func editBegionAction(_ sender: AnyObject) {
        
        searchTextFieldRightConstraint.constant = searchButton.width
        
        UIView.animate(withDuration: 0.2) { 
            self.layoutIfNeeded()
        }
        
    }
    
    @IBAction func searchButtonAction(_ sender: AnyObject) {
        
        // 失去第一响应者
        searchTextField.resignFirstResponder()
        searchTextFieldRightConstraint.constant = 0
        UIView.animate(withDuration: 0.2) {
            self.layoutIfNeeded()
        }
        
    }
    
    // 使用类方法创建 xib 对象
    class func searchView() -> WXSearchView {
        
        return UINib(nibName: "WXSearchView", bundle: nil).instantiate(withOwner: nil, options: nil).last! as! WXSearchView
    }
    
//    override func awakeFromNib() {
//        searchTextField.layer.borderColor = UIColor.orange.cgColor
//        searchTextField.layer.borderWidth = 2
//        searchTextField.layer.cornerRadius = 5
//        searchTextField.layer.masksToBounds = true
//    }
}
